home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / iscan.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.2 KB  |  172 lines

  1. /* Copyright (C) 1992, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: iscan.h,v 1.4 2000/09/19 19:00:46 lpd Exp $ */
  20. /* Token scanner state and interface */
  21. /* Requires gsstruct.h, ostack.h, stream.h */
  22.  
  23. #ifndef iscan_INCLUDED
  24. #  define iscan_INCLUDED
  25.  
  26. #include "sa85x.h"
  27. #include "sstring.h"
  28.  
  29. /*
  30.  * Define the state of the scanner.  Before calling scan_token initially,
  31.  * the caller must initialize the state by calling scanner_state_init.
  32.  * Most of the state is only used if scanning is suspended because of
  33.  * an interrupt or a callout.
  34.  *
  35.  * We expose the entire state definition to the caller so that
  36.  * the state can normally be allocated on the stack.
  37.  */
  38. #ifndef scanner_state_DEFINED
  39. #  define scanner_state_DEFINED
  40. typedef struct scanner_state_s scanner_state;
  41. #endif
  42.  
  43. /*
  44.  * Define a structure for dynamically growable strings.
  45.  * If is_dynamic is true, base/next/limit point to a string on the heap;
  46.  * if is_dynamic is false, base/next/limit point either to the local buffer
  47.  * or (only while control is inside scan_token) into the source stream buffer.
  48.  */
  49. #define max_comment_line 255    /* max size of an externally processable comment */
  50. #define max_dsc_line max_comment_line    /* backward compatibility */
  51. #define da_buf_size (max_comment_line + 2)
  52. typedef struct dynamic_area_s {
  53.     byte *base;
  54.     byte *next;
  55.     byte *limit;
  56.     bool is_dynamic;
  57.     byte buf[da_buf_size];    /* initial buffer */
  58.     gs_memory_t *memory;
  59. } dynamic_area;
  60.  
  61. #define da_size(pda) ((uint)((pda)->limit - (pda)->base))
  62. typedef dynamic_area *da_ptr;
  63.  
  64. /* Define state specific to binary tokens and binary object sequences. */
  65. typedef struct scan_binary_state_s {
  66.     int num_format;
  67.     int (*cont)(P4(i_ctx_t *, stream *, ref *, scanner_state *));
  68.     ref bin_array;
  69.     uint index;
  70.     uint max_array_index;    /* largest legal index in objects */
  71.     uint min_string_index;    /* smallest legal index in strings */
  72.     uint top_size;
  73.     uint size;
  74. } scan_binary_state;
  75.  
  76. /* Define the scanner state. */
  77. struct scanner_state_s {
  78.     uint s_pstack;        /* stack depth when starting current */
  79.                 /* procedure, after pushing old pstack */
  80.     uint s_pdepth;        /* pstack for very first { encountered, */
  81.                 /* for error recovery */
  82.     int s_options;
  83.     enum {
  84.     scanning_none,
  85.     scanning_binary,
  86.     scanning_comment,
  87.     scanning_name,
  88.     scanning_string
  89.     } s_scan_type;
  90.     dynamic_area s_da;
  91.     union sss_ {        /* scanning sub-state */
  92.     scan_binary_state binary;    /* binary */
  93.     struct sns_ {        /* name */
  94.         int s_name_type;    /* number of /'s preceding a name */
  95.         bool s_try_number;    /* true if should try scanning name */
  96.         /* as number */
  97.     } s_name;
  98.     stream_state st;    /* string */
  99.     stream_A85D_state a85d;    /* string */
  100.     stream_AXD_state axd;    /* string */
  101.     stream_PSSD_state pssd;    /* string */
  102.     } s_ss;
  103. };
  104.  
  105. /* The type descriptor is public only for checking. */
  106. extern_st(st_scanner_state);
  107. #define public_st_scanner_state()    /* in iscan.c */\
  108.   gs_public_st_complex_only(st_scanner_state, scanner_state, "scanner state",\
  109.     scanner_clear_marks, scanner_enum_ptrs, scanner_reloc_ptrs, 0)
  110.  
  111. /* Initialize a scanner with a given set of options. */
  112. #define SCAN_FROM_STRING 1    /* true if string is source of data */
  113.                 /* (for Level 1 `\' handling) */
  114. #define SCAN_CHECK_ONLY 2    /* true if just checking for syntax errors */
  115.                 /* and complete statements (no value) */
  116. #define SCAN_PROCESS_COMMENTS 4  /* return scan_Comment for comments */
  117.                 /* (all comments or only non-DSC) */
  118. #define SCAN_PROCESS_DSC_COMMENTS 8  /* return scan_DSC_Comment */
  119. void scanner_state_init_options(P2(scanner_state *sstate, int options));
  120. #define scanner_state_init_check(pstate, from_string, check_only)\
  121.   scanner_state_init_options(pstate,\
  122.                  (from_string ? SCAN_FROM_STRING : 0) |\
  123.                  (check_only ? SCAN_CHECK_ONLY : 0))
  124. #define scanner_state_init(pstate, from_string)\
  125.   scanner_state_init_check(pstate, from_string, false)
  126.  
  127. /*
  128.  * Read a token from a stream.  As usual, 0 is a normal return,
  129.  * <0 is an error.  There are also some special return codes:
  130.  */
  131. #define scan_BOS 1        /* binary object sequence */
  132. #define scan_EOF 2        /* end of stream */
  133. #define scan_Refill 3        /* get more input data, then call again */
  134. #define scan_Comment 4        /* comment, non-DSC if processing DSC */
  135. #define scan_DSC_Comment 5    /* DSC comment */
  136. int scan_token(P4(i_ctx_t *i_ctx_p, stream * s, ref * pref,
  137.           scanner_state * pstate));
  138.  
  139. /*
  140.  * Read a token from a string.  Return like scan_token, but also
  141.  * update the string to move past the token (if no error).
  142.  */
  143. int scan_string_token_options(P4(i_ctx_t *i_ctx_p, ref * pstr, ref * pref,
  144.                  int options));
  145. #define scan_string_token(i_ctx_p, pstr, pref)\
  146.   scan_string_token_options(i_ctx_p, pstr, pref, 0)
  147.  
  148. /*
  149.  * Handle a scan_Refill return from scan_token.
  150.  * This may return o_push_estack, 0 (meaning just call scan_token again),
  151.  * or an error code.
  152.  */
  153. int scan_handle_refill(P6(i_ctx_t *i_ctx_p, const ref * fop,
  154.               scanner_state * pstate, bool save, bool push_file,
  155.               op_proc_t cont));
  156.  
  157. /*
  158.  * Define the procedure "hook" for parsing DSC comments.  If not NULL,
  159.  * this procedure is called for every DSC comment seen by the scanner.
  160.  */
  161. extern int (*scan_dsc_proc) (P2(const byte *, uint));
  162.  
  163. /*
  164.  * Define the procedure "hook" for parsing general comments.  If not NULL,
  165.  * this procedure is called for every comment seen by the scanner.
  166.  * If both scan_dsc_proc and scan_comment_proc are set,
  167.  * scan_comment_proc is called only for non-DSC comments.
  168.  */
  169. extern int (*scan_comment_proc) (P2(const byte *, uint));
  170.  
  171. #endif /* iscan_INCLUDED */
  172.